package cn.iocoder.yudao.module.pickbook.service.classes;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.pickbook.controller.admin.classes.vo.*;
import cn.iocoder.yudao.module.pickbook.dal.dataobject.classes.classesDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.pickbook.dal.mysql.classes.classesMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.pickbook.enums.ErrorCodeConstants.*;

/**
 * 班级 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class classesServiceImpl implements classesService {

    @Resource
    private classesMapper classesMapper;

    @Override
    public Long createclasses(classesSaveReqVO createReqVO) {
        // 插入
        classesDO classes = BeanUtils.toBean(createReqVO, classesDO.class);

        // 手动生成 id
        long id = UUID.randomUUID().getLeastSignificantBits();
        classes.setId(id);

        classesMapper.insert(classes);

        // 返回
        return classes.getId();
    }

    @Override
    public void updateclasses(classesSaveReqVO updateReqVO) {
        // 校验存在
        validateclassesExists(updateReqVO.getId());
        // 更新
        classesDO updateObj = BeanUtils.toBean(updateReqVO, classesDO.class);
        classesMapper.updateById(updateObj);
    }

    @Override
    public void deleteclasses(Long id) {
        // 校验存在
        validateclassesExists(id);
        // 删除
        classesMapper.deleteById(id);
    }

    @Override
        public void deleteclassesListByIds(List<Long> ids) {
        // 删除
        classesMapper.deleteByIds(ids);
        }


    private void validateclassesExists(Long id) {
        if (classesMapper.selectById(id) == null) {
            throw exception(CLASSES_NOT_EXISTS);
        }
    }

    @Override
    public classesDO getclasses(Long id) {
        return classesMapper.selectById(id);
    }

    @Override
    public PageResult<classesDO> getclassesPage(classesPageReqVO pageReqVO) {
        return classesMapper.selectPage(pageReqVO);
    }

}